package com.lancoo.answer.util.paperUtils;

import android.text.TextUtils;
import android.util.Log;

import com.lancoo.answer.model.ConstantBean;
import com.lancoo.answer.model.TaskState;
import com.lancoo.answer.model.bean.Ques;
import com.lancoo.answer.model.entity.TaskControlBean;
import com.lancoo.answer.widget.SplitView;

/**
 * Created by pengmi on 2021/12/16 10:38
 * Description:SplitView上下分屏高度调整工具类
 */
public class SplitViewHeightAdjustTuils {


    public static void splitViewDefaultLoadHeight(Ques ques, SplitView view) {
        String typeNo = ques.getTypeNo();
        String genreID = ques.getGenreID();
        float mSplitRatio = 0.45f;
        if (typeNo == null) {
            return;
        }
        switch (typeNo) {
            case "W"://听写
            case "E"://听力选择
            case "S"://听力填空
            case "G"://听力简答
            case "x":
            case "L":
                if (ConstantBean.Companion.getTaskState() != TaskState.TRAINING) {
                    mSplitRatio = 0.4f;
                } else {
                    float roll = 0f;
                    if (!TextUtils.isEmpty(ques.getAudioSubLeader())) {
                        roll += 0.2f;
                    }
                    mSplitRatio = 0.1f + roll;
                }
                break;
            case "N"://词汇填空、选词填空
                mSplitRatio = 0.2f;
                break;
//            case "k"://
//                mSplitRatio = 0.1f;
//                break;
        }
        if (genreID != null) {
            if (TextUtils.equals("39", genreID) || TextUtils.equals("41", genreID)) {
                TaskControlBean taskControlBean = ConstantBean.Companion.getTaskControlBean();
                if (taskControlBean != null) {
                    float splitHeigthDeviation = taskControlBean.getSplitHeigthDeviation();
                    if (splitHeigthDeviation < mSplitRatio) {
                        mSplitRatio = mSplitRatio - splitHeigthDeviation;
                    }
                }
            }
            if (TextUtils.equals("20", genreID)) {
                mSplitRatio = 0.3f;
            }
        }
        view.setHandlerViewPosition(mSplitRatio);

    }


    public static void splitViewLoadHeightToKeyBoard(Ques ques, SplitView splitView) {
        Log.e("eee","splitViewLoadHeightToKeyBoard"+ques.getTypeNo());
        String typeNo = ques.getTypeNo();
        String genreID = ques.getGenreID();
        if (typeNo == null) {
            return;
        }
        float mSplitRatio = 0.7f;
        switch (typeNo) {
            case "W"://听写
            case "E"://听力选择
            case "N"://词汇填空、选词填空
            case "Q":
                mSplitRatio = 0.5f;
                break;
            case "S"://听力填空
                mSplitRatio = 0.2f;
                break;
//            case "k"://阅读综合
//                mSplitRatio = 0.6f;
//                break;
        }
        if (genreID != null) {
            if (TextUtils.equals("39", genreID) || TextUtils.equals("41", genreID)) {
                TaskControlBean taskControlBean = ConstantBean.Companion.getTaskControlBean();
                mSplitRatio = 0.5f;
                if (taskControlBean != null) {
                    float splitHeigthDeviation = taskControlBean.getSplitHeigthDeviation();
                    if (splitHeigthDeviation < mSplitRatio) {
                        mSplitRatio = mSplitRatio - splitHeigthDeviation;
                    }

                }
            }
        }
        splitView.forceAdjsutAnswerHeight(mSplitRatio);
    }
}
